// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:flutter/material.dart';
import '../../utils/Global.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class HomeCourse extends StatefulWidget {
  List courseList;
  HomeCourse({
    Key? key,
    required this.courseList,
  }) : super(key: key);

  @override
  State<HomeCourse> createState() => _HomeCourseState();
}

class _HomeCourseState extends State<HomeCourse> {
  @override
  Widget build(BuildContext context) {
    return SliverList(
      delegate: SliverChildBuilderDelegate((BuildContext context, index) {
        // widget.courseList[index] 取到单个课程的信息
          var course = widget.courseList[index];
          return GestureDetector(
            onTap: () {
              print(index);
              /// 跳转到课程详情
              Map<String, dynamic> p = {
                'id': course['id'],
                'title': course['courseName']!
              };
              print("$p 传参");
              G.router?.navigateTo(context, "/courseDetail" + G.parseQuery(params: p));
            },
            child: Container(
              color: Colors.white,
              padding: EdgeInsets.all(10),
              child: Flex(
                direction: Axis.horizontal,
                children: [
                  Expanded(
                    flex: 1,
                    child:  ClipRRect(
                      borderRadius: BorderRadius.circular(10),
                      child: Image.network(
                        course['courseImgUrl'],
                        fit: BoxFit.cover,
                        height: 200.h,
                      ),
                    ),
                  ),
                  Expanded(
                    flex: 3,
                    child: Container(
                     
                      height: 200.h,
                      padding: EdgeInsets.symmetric(horizontal: 16),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Container(
                            width: double.infinity,
                            child: Text(
                              course['courseName'],
                              style: const TextStyle(
                                fontSize: 16.0,
                              ),
                            ),
                          ),
                          Container(
                            width: double.infinity,
                            child: Text(
                              course['brief'],
                              style: const TextStyle(
                                fontSize: 14.0,
                                
                              ),
                            ),
                          ),
                          Row(children: [
                            Container(
                              color: Colors.grey[200],
                              padding: EdgeInsets.all(5),
                              child: Text(
                                course['teacherDTO']['teacherName']
                              ),
                            ),
                            const SizedBox(width: 10,),
                            Container(
                              color: Colors.grey[200],
                              padding: EdgeInsets.all(5),
                              child: Text(
                                course['teacherDTO']['description']
                              ),
                            )
                          ],),
                          Row(children: [
                            Container(
                              child: Text(
                               '¥' + course['price'].toString(),
                                style: TextStyle(
                                  fontSize: 14.0,
                                  color: Colors.red ,
                                  // fontWeight: FontWeight.w500
                                ),
                              ),
                            ),
                            const SizedBox(width: 10),
                            Container(
                              child: Text(
                                course['sales'].toString() + '人购买',
                                style: TextStyle(
                                  fontSize: 12.0
                                ),
                              ),
                            )
                          ],)
                        ],
                      ),
                    ),
                  )
                ],
              ),
            ),
          );
        },
        childCount: widget.courseList.length
      ),
    );
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }
}